import moment from "@/common/moment.js"
import { week } from '@/utils/date'
/**
 * 
 * @param {*} start 
 * @param {*} end 
 * @returns 
 */
export const calendar = () => {
  const curDate = new Date()
  const date = new Date()
  const arr = []

  date.setMonth(curDate.getMonth() + 1)
  date.setDate(0)
  const curMonthDays = date.getDate()
  // console.log('本月天数：', curMonthDays);
  curDate.setDate(date.getDate())

  date.setDate(1)
  const firstDayWeek = date.getDay()
  // console.log('本月第一天：', week(firstDayWeek, '0'));
  for(let i = 0; i < curMonthDays; i++) {
    date.setDate(i + 1)
    arr.push({
      week: date.getDay(),
      date: moment(date).format('YYYY-MM-DD'),
      value: moment(date).format('DD'),
      curMonth: true
    })
  }


  date.setDate(curMonthDays)
  const lastDayWeek = date.getDay()
  // console.log('本月最后一天：', week(lastDayWeek, '0'))


  date.setMonth(curDate.getMonth())
  date.setDate(0)
  const preMonthDays = date.getDate()
  // console.log('上月天数：', preMonthDays);

  date.setMonth(curDate.getMonth() - 1)
  for(let i = 0; i < firstDayWeek - 1; i++) {
    date.setDate(preMonthDays - i)
    arr.unshift({
      week: date.getDay(),
      date: moment(date).format('YYYY-MM-DD'),
      value: moment(date).format('DD'),
      curMonth: false
    })
  }

  date.setMonth(curDate.getMonth() + 1)
  for(let i = 0; i < (7 - lastDayWeek); i++) {
    date.setDate(i + 1)
    arr.push({
      week: date.getDay(),
      date: moment(date).format('YYYY-MM-DD'),
      value: moment(date).format('DD'),
      curMonth: false
    })
  }
  
  return arr
}